package com.myblog.service.impl;

import com.myblog.mapper.ArticleMapper;
import com.myblog.mapper.CommentMapper;
import com.myblog.mapper.LeaveMapper;
import com.myblog.mapper.TagMapper;
import com.myblog.service.SiteInfoService;
import com.myblog.utils.DataMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class SiteInfoServiceImpl implements SiteInfoService {
    @Autowired
    private ArticleMapper articleMapper;

    @Autowired
    private TagMapper tagMapper;

    @Autowired
    private CommentMapper commentMapper;

    @Autowired
    private LeaveMapper leaveMapper;
    @Override
    public DataMap getSiteInfo() {
        Integer numOfArticle = articleMapper.selectNumOfArticle();
        Integer numOfTags = tagMapper.selectNumOfTags();
        Integer numOfComment = commentMapper.selectNumOfComment();
        Integer numOfLeaveWord = leaveMapper.selectNumOfLeaveWord();

        HashMap<String,Object> result = new HashMap<>();
        result.put("articleNum",numOfArticle);
        result.put("tagsNum",numOfTags);
        result.put("leaveWordNum",numOfComment);
        result.put("commentNum",numOfLeaveWord);
        return DataMap.success().setData(result);
    }
}
